package com.advaita.license;

import java.awt.Component;
import java.awt.Container;
import java.awt.EventQueue;
import java.util.ArrayList;
import java.util.List;

import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JButton;
import javax.swing.border.EtchedBorder;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Example {

	private static final ArrayList<Selection[]> SelectionOptions = new ArrayList<Selection[]>();
	private JFrame frame;
	private JList list1;
	private DefaultListModel listModel1 = new DefaultListModel();
	private JList list2;
	private DefaultListModel listModel2 = new DefaultListModel();
	private int selectedButton = 0;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Example window = new Example();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public Example() {
		//initialize();
		//initialize_SelectionOptions();
		//CreateSelections();
		//SetUpSelections();
	}

	/*
	 *  Initialize the contents of the frame.
	*/
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 775, 561);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);

		list1 = new JList(listModel1);
		list1.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
		list1.setBounds(50, 60, 171, 339);
		frame.getContentPane().add(list1);

		list2 = new JList(listModel2);
		list2.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
		list2.setBounds(391, 60, 171, 339);
		frame.getContentPane().add(list2);

		JButton btnNewButton = new JButton(">>");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				MoveSelectionRight();
			}
		});
		btnNewButton.setBounds(257, 91, 89, 23);
		frame.getContentPane().add(btnNewButton);

		JButton btnNewButton_1 = new JButton("<<");
		btnNewButton_1.setBounds(257, 154, 89, 23);
		frame.getContentPane().add(btnNewButton_1);
		
		JButton btnOrganism = new JButton("Organism");
		btnOrganism.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				LoadSelections(0);
			}
		});
		btnOrganism.setBounds(50, 11, 89, 23);
		frame.getContentPane().add(btnOrganism);
		
		JButton btnNewButton_3 = new JButton("MicroArray");
		btnNewButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				LoadSelections(1);
			}
		});
		btnNewButton_3.setBounds(210, 11, 89, 23);
		frame.getContentPane().add(btnNewButton_3);
	}

/*
	private void CreateSelections() {
		for (int i = 0; i < 10; i++) {
			Selection selection = new Selection();
			selection.setSelection("Selection" + i);
			selection.setIsEnabled(false);
			selections.add(selection);
		}
	}
*/
	private void initialize_SelectionOptions() {
/*		Selection[] Organism = {
				new Selection("Homo sapien", false), 
				new Selection("Mus muculus", false),
				new Selection("Rattus novegicus", false),
				new Selection("Arabidopsis thaliana (Thale cress)", false),
				new Selection("Drosophilla melanogaster (Fruit Fly)", false),
				new Selection("Canis lupus familiaris (Dog)",  false),
				new Selection("Danio rerio (Zebrafish)", false),
				new Selection("Caenorhabiditus elegans (Nematode)", false),
				new Selection("Gallus gallus (chicken)", false),
				new Selection("Bos taurus (Cow/Bovine)", false),
				new Selection("Sus scrofa domesticus (Pig)", false)
				};

		Selection[] MicroArray = {
				new Selection("Affymatrix", false), 
				new Selection("Applied Biosystems",false),
				new Selection("HitachiSoft", false), 
				new Selection("Illumina", false),
				new Selection("Invitrogen", false),
				new Selection("Miltenyl Biotech",false),
				new Selection("NimbleGen", false),
				new Selection("Agilent Technologies", false),
				new Selection("Ocimum Biosolutions",false),
				new Selection("Operon", false),
				new Selection("Phalanx Biotech", false),
				new Selection("Rosetta Inpharmatics/Merck Parmaceuticals", false)
				};

		Selection[] Geneid = {
				new Selection("Entrez", false), 
				new Selection("Gene Symbol", false), 
				new Selection("GeneBank Accession",false), 
				new Selection("GeneBank Gis", false), 
				new Selection("Ensemble", false), 
				new Selection("Probe ID", false)
				};

		Selection[] PathwayDB = { 
				new Selection("Reactome", false), 
				new Selection("KEGG", false)
				};

		Selection[] Analysis = { 
				new Selection("DE Genes Impact Analysis",false), 
				new Selection("DE Genes Coherent Chains of Perturbation", false), 
				new Selection("All Genese Impact Analysis", false), 
				new Selection("All Genes with GSA & PADOG", false)
				 };

		SelectionOptions.add(Organism);
		SelectionOptions.add(MicroArray);
		SelectionOptions.add(Geneid);
		SelectionOptions.add(PathwayDB);
		SelectionOptions.add(Analysis);
		
		LoadSelections(0);
*/
		}
	
	/*
	public void SetUpSelections() {
		for (Selection selection : selections) {
			if (selection.getIsEnabled()) {
				listModel2.addElement(selection.getSelection());
			} else {
				listModel1.addElement(selection.getSelection());
			}
		}
	}
	*/

	private void LoadSelections(int selected)
	{
		listModel1.clear();
		listModel2.clear();
		for (Selection selection : SelectionOptions.get(selected)) {
			if (selection.getIsEnabled()) {
				listModel2.addElement(selection.getSelection());
			} else {
				listModel1.addElement(selection.getSelection());
			}
		}
	}
	
	private void MoveSelectionRight() {
		int selectedIndex = list1.getSelectedIndex();
		Object sel = list1.getSelectedValue();
	}
}
